﻿Public Class RegexGroupsViewModel
    Inherits RegexViewModelBase
    Implements IEnumerable

#Region "Events"
    ' Insert Event Declarations Here
#End Region

#Region "Properties"
#Region "Constants"
    ' Insert Constant Declarations Here
#End Region

    Private _groups As GroupCollection
    Public Property Groups() As GroupCollection
        Get
            Return _groups
        End Get
        Private Set(ByVal value As GroupCollection)
            _groups = value
        End Set
    End Property

    Private _groupsViewModels As IEnumerable
    Public Property GroupsViewModels() As IEnumerable
        Get
            Return _groupsViewModels
        End Get
        Private Set(ByVal value As IEnumerable)
            _groupsViewModels = value
        End Set
    End Property

    Public ReadOnly Property Count As Integer
        Get
            'Subtract 1 because the first item is always the original Match (which is not included in the collection)
            Return Me.Groups.Count - 1
        End Get
    End Property

    Public Overrides ReadOnly Property Index As Integer
        Get
            If Me.Groups.Count > 0 Then
                Return Me.Groups(0).Index
            Else
                Return 0
            End If
        End Get
    End Property

    Public Overrides ReadOnly Property Length As Integer
        Get
            If Me.Groups.Count > 0 Then
                Return Me.Groups(0).Length
            Else
                Return 0
            End If
        End Get
    End Property
#End Region

#Region "Constructors"
    Public Sub New(groups As GroupCollection, regex As Regex, viewNavigator As IViewNavigator)
        MyBase.New(regex, viewNavigator)

        Me.Groups = groups
        Me.GroupsViewModels =
            New IEnumerable() {
                    New RegexNamedGroupsViewModel(groups, regex, viewNavigator),
                    New RegexNumberedGroupsViewModel(groups, regex, viewNavigator)
                }
    End Sub
#End Region

#Region "Methods"
    Private Function GetEnumerator1() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
        Return Me.GroupsViewModels.GetEnumerator()
    End Function

#Region "Event Raiser Methods"
    ' Insert Method Declarations which Raise an Event Here
#End Region

#Region "Event Handlers"
    ' Insert Method Declarations which Handle an Event Here
#End Region
#End Region

End Class
